 //82.删除排序链表中的重复元素II
 //https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/?envType=daily-question&envId=2024-01-15
class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
        if(!head || !head->next) return head;
        unordered_map<int,int> hash;
        ListNode* cur = head;
        while(cur) 
        {
            ++hash[cur->val];
            cur = cur->next;
        }

        ListNode* link = new ListNode;
        cur = link;
        while(head)
        {
            if(hash[head->val] == 1)
            {
                cur->next = head;
                cur = cur->next;
            }
            head = head->next;
        }
        cur->next=nullptr;
        cur = link->next;
        delete link;
        return cur;
    }
};